<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="bzZuZhang" style="height: 100%;width: 100%">
    <div style="height:93%">
        <!--奖金表格-->
        <table id="bzZuZhangTable"></table>
    </div>
    <div id="bzZuZhangTableToolbar" style="display: none;">
        <div style="width: 350px;">
            <a class="easyui-linkbutton c4" style="height: 90%" data-options="plain:true" onClick="bzZuZhangTableInit()"><i class="fa fa-plus-square fa-fw" aria-hidden="true"></i>刷新</a>
            <a class="easyui-linkbutton"  data-options="plain:true">|</a>
            <a class="easyui-linkbutton c1" style="height: 90%" data-options="plain:true" onclick="javaScript:$('#bzZuZhangTable').edatagrid('saveRow')"><i class="fa fa-floppy-o fa-fw" aria-hidden="true"></i>保存</a>
            <a class="easyui-linkbutton" data-options="plain:true">|</a>
            <a class="easyui-linkbutton c6" style="height: 90%" data-options="plain:true" onClick="javaScript:$('#bzZuZhangTable').edatagrid('addRow')"><i class="fa fa-plus-square fa-fw" aria-hidden="true"></i>新增</a>
            <a class="easyui-linkbutton" data-options="plain:true">|</a>
            <a class="easyui-linkbutton c5" style="height: 90%" data-options="plain:true" onclick="javaScript:$('#bzZuZhangTable').edatagrid('destroyRow')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>删除</a>
        </div>
    </div>
    <script>
        //当前编辑行的索引
        var baoZhuangCheJianZuZhangIndex=0

       function toLoadBzZuZhang(){
           bzZuZhangTableInit()
       }

        bzZuZhangTableInit()
        function bzZuZhangTableInit() {
            var currentYM=bzcj_currentYear+"年"+bzcj_currentMonth+"月";
            var columns = [//表头
                [
                    {"title": ' <span style="font-size: 18px">组长综合绩效奖金申请表</span><span style="color: #009E94">（效率奖金 +损耗率奖金+规范化奖金+质量奖金）*出勤率+发现异常奖金-违规扣款</span>',"align": "center", "colspan":23},

                ],
                [  {"title": '考核部门（科室）:',"align": "center", "colspan":3},
                    {"field": 'id3', "title": "生产部/包装车间","align": "center", "colspan":2},
                    {"title": '', "align": "center","colspan":13},
                    {"title": '考核周期:',"align": "center","colspan":3},
                    {"field": 'id2', "title": currentYM, "align": "center","colspan":2},
                ],
                [
                    {"field": 'id', "title": 'ID', "width": 30, "align": "center", "hidden": "true"},
                    {"field": 'empName', "title": '姓名', "width": 30, "align": "center","editor":{"type": "text"}},
                    {"field": 'empCode', "title": '工号', "width": 30, "align": "center","editor":{"type": "text"}},
                    {"field": 'zhuGuanName', "title": '所属主管', "width": 30, "align": "center","editor":{"type": "text"}},
                    {"field": 'postName', "title": '岗位名称', "width": 30, "align": "center","hidden": "true"},
                    {"field": 'empGroup', "title": '产线', "width": 30, "align": "center","editor": {"type": "combobox", "options": {"panelHeight":"auto","valueField":"v","textField":"t","data":[{"v":"A","t":"A"},{"v":"B","t":"B"}]}}},
                    {"field": 'assessType', "title": '绩效类型', "width": 30, "align": "center","hidden": "true"},
                    {"field": 'teamEfficiency',"title": '产线生产<br/>效率(%)',"width": 30,"align": "center",
                        "editor": {"type": "textbox", "options": {"onChange":baoZhuangCheJianuZuZhangProductivity}}},
                    {"field": 'performanceBonusNorm', "title": '绩效奖金<br/>标准', "width": 30,"align": "center","editor": {"type": "textbox", "options": {"readonly":true}}},
                    {"field": 'efficiencyBonus', "title": '效率奖金', "width": 30,"align": "center","editor": {"type": "textbox", "options": {"onChange":totalBaoZhuangZuZhang}}},
                    {"field": 'lossRate', "title": '损耗率', "width": 30,"align": "center","editor": {"type": "textbox", "options": {"onChange":baoZhuangCheJianZuZhangLossRate}}},
                    {"field": 'lossBonus', "title": '损耗率<br/>奖金', "width": 30,"align": "center","editor": {"type": "textbox", "options": {"onChange":totalBaoZhuangZuZhang}}},
                    {"field": 'score5s', "title": '5s得分', "width": 30,"align": "center","editor": {"type": "textbox", "options":  {"onChange":baoZhuangCheJianZuZhangScore5s}}},
                    {"field": 'penalty5s', "title": '规范化<br/>奖金', "width": 30,"align": "center","editor": {"type": "textbox", "options": {"onChange":totalBaoZhuangZuZhang}}},
                    {"field": 'penaltyDayRate', "title": '质量天数<br/>比率(%)', "width": 30,"align": "center","editor": {"type": "textbox", "options": {"onChange":baoZhuangCheJianZuZhangPenaltyDayRate}}},
                    {"field": 'penaltyBonusNorm', "title": '质量奖金<br/>标准', "width": 30,"align": "center","editor": {"type": "textbox", "options": {"onChange":baoZhuangCheJianZuZhangPenaltyBonusNorm}}},
                    {"field": 'penaltyBonus', "title": '质量奖金', "width": 30,"align": "center","editor": {"type":"textbox","options": {"onChange":totalBaoZhuangZuZhang}}},
                    {"field": 'performanceBonus', "title": '绩效奖金', "width": 30,"align": "center","editor": {"type":"textbox", "options": {"readonly":true}}},
                    {"field": 'attendanceRate', "title": '出勤率<br/>(%)', "width": 30,"align": "center","editor": {"type":"textbox", "options": {"onChange":totalBaoZhuangZuZhang}}},
                    {"field": 'exceptionBonus', "title": '发现异常<br/>奖金', "width": 30,"align": "center","editor": {"type": "textbox", "options": {"onChange":totalBaoZhuangZuZhang}}},
                    {"field": 'illegalFine', "title": '违规扣款', "width": 30,"align": "center","editor": {"type":"textbox", "options": {"onChange":totalBaoZhuangZuZhang}}},
                    {"field": 'resultMoney', "title": '综合<br/>绩效（元）', "width": 30,"align": "center","editor": {"type": "textbox", "options": {"readonly":true}}},
                    {"field": 'remarks', "title": '备注', "width": 130,"align": "center","editor": {"type":"textarea"}},
                ]]
            var datas=commonAjax("post","/jx/bzcj/selectJxAssessBzcj",{postId:JX_BZCJ_ZUZHANG_CODE,assessType:2,empZuzhang:JX_BZCJ_ZUZHANG,year:bzcj_currentYear,month:bzcj_currentMonth,pkDept:bzcj_currentDept})
            //奖金基数表格
            $("#bzZuZhangTable").edatagrid({
                nowrap: false,
                columns: columns,
                data:datas,
                showFooter: true,
                autoSave:true,
                fitColumns: true,
                //scrollbarSize:0,  //最右侧多出来的去除
                toolbar:"#bzZuZhangTableToolbar",
                onBeforeEdit:function (index, row) { //编辑器打开触发事件
                    baoZhuangCheJianZuZhangIndex=index;//保存当前索引

                },
                onAfterEdit:function (index, row) {
                   loadFooter();
                },
                onDestroy:function (index,row) { //删除一行触发事件
                   loadFooter();
                }

            })
            loadFooter();
        }

        //产线生产效率触发事件:计算绩效奖金标准
        function baoZhuangCheJianuZuZhangProductivity(newValue,oldValue) {
            if(newValue){
                //赋值绩效奖金标准基数
                var rEfficiencyBonus=0;
                //若当月包装车间生产效率＜98%时，则当月质量奖基数为300元
                var penaltyBonusNorm=300;
                if (newValue>=98 && newValue<100){
                    rEfficiencyBonus=780;
                    penaltyBonusNorm=780;

                }else if (newValue>=100 && newValue<105 ){
                    rEfficiencyBonus=880;
                    penaltyBonusNorm=880;
                }else if (newValue>=105){
                    rEfficiencyBonus=1000;
                    penaltyBonusNorm=1000;
                }
                //赋值绩效奖金标准
                getEditObjectZuZHang("performanceBonusNorm").textbox("setValue",rEfficiencyBonus);
                //赋值效率奖金
                getEditObjectZuZHang("efficiencyBonus").textbox("setValue",rEfficiencyBonus*0.45);
                //赋值质量奖金标准
                getEditObjectZuZHang("penaltyBonusNorm").textbox("setValue",penaltyBonusNorm);
            }

        }

        //损耗率触发事件：计算损耗奖金
        function baoZhuangCheJianZuZhangLossRate(newValue,oldValue){
            newValue=newValue?Number(newValue):0;
            var result=0;
            var performanceBonusNorm=Number(getEditObjectZuZHang("performanceBonusNorm").textbox("getValue")); //绩效奖金标准
            //损耗率 小于99：绩效奖金0；(包括)99~100之间：绩效奖金*0.05;等于100：绩效奖金*0.05，
            if (newValue==100){
                result=performanceBonusNorm*0.05;
            }
            if (newValue>=99 && newValue<100){
                result=performanceBonusNorm*0.03;
            }
            getEditObjectZuZHang("lossBonus").textbox("setValue",fomatFloat(result,2));  //赋值损耗率奖金
        }

        //5s得分触发事件：计算规范化奖金
        function baoZhuangCheJianZuZhangScore5s(newValue,oldValue){
            var result=0;
            newValue=newValue?Number(newValue):0;
            //大于或等于85：绩效奖金标准*0.05
            if (newValue>=85){
                var performanceBonusNorm=Number(getEditObjectZuZHang("performanceBonusNorm").textbox("getValue")) //绩效奖金标准
                result=performanceBonusNorm*0.05
            }
            var penalty5s= getEditObjectZuZHang("penalty5s");   //规范化奖金
            penalty5s.textbox("setValue",fomatFloat(result,2));
        }

        //质量天数比率(%)触发事件：计算质量奖金
        function baoZhuangCheJianZuZhangPenaltyDayRate(newValue,oldValue){
            //调用质量奖金标准事件
            baoZhuangCheJianZuZhangPenaltyBonusNorm(getEditObjectZuZHang("penaltyBonusNorm").textbox("getValue"));
        }

        //质量奖金标准触发事件：计算质量奖金
        function baoZhuangCheJianZuZhangPenaltyBonusNorm(newValue,oldValue){
            newValue=newValue?Number(newValue):0;
            var penalty5s= getEditObjectZuZHang("penaltyDayRate").textbox("getValue") //质量天数比率
            penalty5s=penalty5s?Number(penalty5s)/100:0;
            var penaltyBonus=getEditObjectZuZHang("penaltyBonus")   //质量奖金
            penaltyBonus.textbox("setValue",fomatFloat((penalty5s*newValue*0.45),2))

        }

        //合计综合绩效
        function totalBaoZhuangZuZhang(newValue,oldValue) {
            //初始效率高点: 注意：js的0相等于空字符串和false，js的1相等于字符串"1"、true;0==false==""   1==true="1" 所以不要去判断了
            if (newValue!= undefined || newValue!= null){
                var efficiencyBonus=getEditObjectZuZHang("efficiencyBonus").textbox("getValue"); //效率奖金
                efficiencyBonus=efficiencyBonus?Number(efficiencyBonus):0;
                var lossBonus=getEditObjectZuZHang("lossBonus").textbox("getValue");      //损耗奖金
                lossBonus=lossBonus?Number(lossBonus):0;
                var penalty5s=getEditObjectZuZHang("penalty5s").textbox("getValue");       //规范奖金
                penalty5s=penalty5s?Number(penalty5s):0;
                var penaltyBonus=getEditObjectZuZHang("penaltyBonus").textbox("getValue");//质量奖金
                penaltyBonus=penaltyBonus?Number(penaltyBonus):0;
                var attendanceRate=getEditObjectZuZHang("attendanceRate").textbox("getValue"); //出勤率
                attendanceRate=attendanceRate?Number(attendanceRate)/100:1;
                var exceptionBonus=getEditObjectZuZHang("exceptionBonus").textbox("getValue"); //发现异常奖金
                exceptionBonus=exceptionBonus?Number(exceptionBonus):0;
                var illegalFine=getEditObjectZuZHang("illegalFine").textbox("getValue");      //违规扣款
                illegalFine=illegalFine?Number(illegalFine):0;
                var performanceBonus=getEditObjectZuZHang("performanceBonus");       //绩效奖金
                var bonus  = efficiencyBonus+lossBonus+penalty5s+penaltyBonus;
                performanceBonus.textbox("setValue",fomatFloat(bonus,2))
                var resultMoney=getEditObjectZuZHang("resultMoney");       //最终绩效奖金
                resultMoney.textbox("setValue",fomatFloat(bonus*attendanceRate+exceptionBonus-illegalFine,2))
            }
        }

        //加载页脚行
        function loadFooter(){
            var resultMoney=0;
            var rows = $("#bzZuZhangTable").datagrid("getRows");
            if (rows){
                rows.forEach(function (val) {
                    resultMoney+= Number(val.resultMoney);
                })
            }
            resultMoney=fomatFloat(resultMoney,2);
            $("#bzZuZhangTable").datagrid("reloadFooter",[
                {"empCode":"合计","resultMoney":resultMoney},
            ])
        }

        //获取当前编辑行指定的jquery对象
        function getEditObjectZuZHang(fieldValue) {
            var j = $('#bzZuZhangTable').datagrid('getEditor', {
                index: baoZhuangCheJianZuZhangIndex,
                field: fieldValue
            }).target; //编辑器对象
            return j
        }
    </script>
</div>
</body>
</html>